from flask import Blueprint, jsonify, request
from xlrd import open_workbook
import os
from utile.myfile import myf

bp_p9bp = Blueprint('p9bp',__name__)


@bp_p9bp.route('/upload',methods=['POST'])
def upload():
    # 获取文件
    file = request.files['file']
    newname = myf.rename(file.filename)
    # 上传文件
    file.save(os.path.join('./static/files/' + newname))
    # 打开文件读取
    # newname = 'ac6844d376e24a2a9bd96f30b985807a.xls'
    # name = './static/files/' + newname
    # # 封装数据写入数据库
    # bk = open_workbook(name, encoding_override='utf-8')
    # sh = bk.sheets()[0]
    # nrows = sh.nrows
    # print(nrows)
    # ncols = sh.ncols
    # print(ncols)
    # for i in range(2, nrows):
    #     row_date = sh.row_values(i)
    #     for j in range(0, ncols):
    #         print(row_date[j])
    return 'ok'
